﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MusicMaker
{
    public class Sound
    {
        public int[] data;
        public int smaple_rate;
        public Sound(int length, int[] _data, int _sample_rate)
        {
            data = new int[length];
            data = _data;
            smaple_rate = _sample_rate;
        }

        public Sound(int length, int _sample_rate)
        {
            data = new int[length];
            smaple_rate= _sample_rate;
        }

        public Sound Add(Sound sound)
        {
            Sound result = new Sound(data.Length, data, smaple_rate);
            for(int i = 0; i < data.Length; i++)
            {
                result.data[i] += sound.data[i];
            }
            return result;
        }

        public Sound Add(Sound sound, int offset)
        {
            Sound result = new Sound(Math.Max(sound.data.Length + offset, data.Length), smaple_rate);
            for(int i = 0; i < data.Length; i++)
            {
                result.data[i] = data[i];
            }

            for(int i = 0; i < sound.data.Length; i++)
            {
                result.data[i + offset] += sound.data[i];
            }

            return result;
        }

        public static Sound Add(Sound sound1, Sound sound2)
        {
            Sound sound = new Sound(Math.Max(sound1.data.Length, sound2.data.Length), sound1.smaple_rate);
            for( int i = 0; i < sound1.data.Length; i++)
            {
                sound.data[i] = sound1.data[i] + sound2.data[i];
            }
            return sound;
        }
    }
}
